package com.resou.reader.bookstore.freezone;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.resou.reader.R;
import com.resou.reader.base.ResouBaseActivity;
import com.resou.reader.bookstore.freezone.fragment.BoyFragment;
import com.resou.reader.bookstore.freezone.fragment.GirlFragment;
import com.resou.reader.mine.adapter.ViewPagerAdapter;
import com.resou.reader.view.MagincIndicatorAdapter;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 免费专区
 */
public class FreezoneActivity extends ResouBaseActivity implements ViewPager.OnPageChangeListener {

    /**
     * 启动页面方法
     *
     * @param context
     */
    public static void start(Context context) {
        Intent starter = new Intent(context, FreezoneActivity.class);
        context.startActivity(starter);
    }

    @BindView(R.id.ivBack)
    ImageView ivBack;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.mViewPager)
    ViewPager mViewPager;
    @BindView(R.id.mMagicIndicator)
    MagicIndicator mMagicIndicator;
    List<Fragment> fragmentList;
    ViewPagerAdapter viewPagerAdapter = null;
    List<String> list;

    @Override
    protected void initStatusBar() {
    }

    @Override
    protected void initPresenter() {
    }

    @Override
    protected void initView() {
        tvTitle.setText("免费专区");
        fragmentList = new ArrayList<>();
        list = new ArrayList<>();
        list.add("男生频道");
        list.add("女生频道");
        fragmentList.add(BoyFragment.newInstance());
        fragmentList.add(GirlFragment.newInstance());
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        mViewPager.setAdapter(viewPagerAdapter);
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdjustMode(true);
        commonNavigator.setAdapter(new MagincIndicatorAdapter(list, mViewPager));
        mMagicIndicator.setNavigator(commonNavigator);
        ViewPagerHelper.bind(mMagicIndicator, mViewPager);
        mViewPager.addOnPageChangeListener(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_freezone;
    }

    @Override
    public void retryRefreshData() {

    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {
    }

    @Override
    public void onPageSelected(int i) {
    }

    @Override
    public void onPageScrollStateChanged(int i) {
    }

    @OnClick({R.id.ivBack})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivBack:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
        ClassicsFooter.REFRESH_FOOTER_NOTHING = "没有更多数据了";
    }

    @Override
    protected void onResume() {
        super.onResume();
        ClassicsFooter.REFRESH_FOOTER_NOTHING = "没有更多了，去其他频道逛逛吧";
    }
}
